package com.time.config;

import com.time.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 张龙佼
 * @Description springboot相关配置
 * @since 2020-10-14
 */

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //登录拦截器
        InterceptorRegistration ir = registry.addInterceptor(new LoginInterceptor());

        // 拦截所有
        ir.addPathPatterns("/**");

        // 放行首页
        ir.excludePathPatterns("/index")
                // 放行登录和注册
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/verification")
                .excludePathPatterns("/user/register")
                // 放行所有静态资源
                .excludePathPatterns("/images/**")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/scripts/**")
                // 放行商品展示
                .excludePathPatterns("/product/category")
                .excludePathPatterns("/product/product_info")
                // 放行新闻展示
                .excludePathPatterns("/news/news_info");
    }
}
